package com.zxh.baidu;

import com.zxh.util.Constant;
import com.zxh.util.HttpPoolUtil;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.log4j.Logger;

/**
 * Created by zhangxh on 2016/7/12.
 */
public class XiaoDu {
    private static Logger logger=Logger.getLogger(XiaoDu.class);
    private static XiaoDu xiaoDu=new XiaoDu();
    private XiaoDu(){}
    public static XiaoDu instance(){
        return xiaoDu;
    }
    public String askRemote(String question) {
        logger.debug("请求问题："+question);
        String httpRes= HttpPoolUtil.getRetStr(Constant.getXDUri(),new BasicHeader("Cookie", Constant.getXDCookie()),
                new BasicNameValuePair("request_query", question));
        logger.debug("问题："+question+"\r\n返回："+httpRes);
        //		return new JSONObject(httpRes).getJSONArray("result_list").getJSONObject(0).getJSONObject("result_content").getString("answer");
//        String ask=new JSONObject(new JSONObject(httpRes).getJSONArray("result_list").getJSONObject(0).get("result_content").toString()).getString("answer");

//        return ask.replaceAll("小度", "那B小心").replaceAll("百度", "果果");
        return httpRes;
    }
}
